#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tree.h"

#define FILENAME "/home/ll/text"

/*将广义表的数据以树的结构画出来
 *
 *
 */

	tree_st *load_(FILE *fp)
{
	tree_st *root = NULL;
	int c;
	c = fgetc(fp);
	if(c != '(')
	{
		fprintf(stderr,"fgetc() is error\n");
		exit(1);
	}
	
	c = fgetc(fp);
	if(c == ')')
		return NULL;
	root = malloc(sizeof(*root));
	if(root == NULL)
		return NULL;
	root->data = c;
	root->lchild = load_(fp);
	root->rchild = load_(fp);
	fgetc(fp);
	return root;
}


	tree_st *load(const char *path)
{
	tree_st *root;
	FILE *fp = NULL;
	fp = fopen(path,"r");
	if(fp == NULL)
		return NULL;
	root = load_(fp);
	fclose(fp);
	return root;
}

	int main()
{
	tree_st *tree = NULL;
		
	tree = load(FILENAME);
	tree_draw(tree);
	exit(0);
}
